<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>积分提现</title>
	<link rel="stylesheet" href="normalize-css/normalize.css">
	<link rel="stylesheet" href="css/style.css">
	<script src="js/zepto.min.js"></script>
</head>
<body>
	<div class="section withdrawals integra">
		<div class="card">
			<span class="title text-color-1">提现到银行卡</span>
      <a  href="integralWD" style="float:right;font-size:10px;">点击更换提现到银行卡</a>

			<div class="option-item panel">
        <label for="alipayNum">手机号码：</label>
				<input maxlength="11" class="account" name="alipayNum" type="text"/>
			</div>

			<div class="input-item-large">
				<div class="input-item-wrap">
					<label for="price">提现积分</label>
				<input type="number" name="price" id="price" placeholder="请输入提现的积分数">
				</div>
				<span class="note">当前剩余积分为<span class="jifen">1200</span>，<span class="huilv">2</span>积分=1元</span>
			</div>
			<p class="result">积分兑换成现金为： <span class="price"><span class="number">0</span>元</span></p>
			<button>提现</button>
		</div>
	</div>
</body>
</html>
<script>
$(document).ready(function(){

	//发出积分提现的post请求，请求参数，支付宝账号account + 积分数integration
	var withdrawlsURL = "/withdrawls";


	$(".huilv").text(sessionStorage.rate);
  $(".jifen").text(sessionStorage.integral);
  $("#price").on("change",function(){
    $(".number").text($("#price").val()/sessionStorage.rate);
  });
	function checkPhone(phone){
    if(!(/^1[34578]\d{9}$/.test(phone))){
        alert("手机号码有误，请重填");
        return false;
    }
		return true;
	}
	$(".balance").text(sessionStorage.balance);
	$("button").click(function(){
		var money = parseInt($("#price").val());
		var account = $(".account").val();
		if(checkPhone(account)){
			if (money<=parseInt(sessionStorage.integral) && money!="") {
				$.post(withdrawlsURL,{
						integration:money,
						account:account
					},function(res){
						alert(res.resultInfo);
				});
			}
			else {
				alert("最多提现"+sessionStorage.integral+"个积分");
			}
		}
	});
});
</script>
